/************************************************************
 *This file is part of Searcj_PRJ.
 *
 * This program is free.
 *
 * @file    create_dict_index.h
 * @brief   to create dict and index, expecially for keywords recommend
 *
 * @author  Dgg
 * @email   1390713385@qq.com
 * @version 0.0.1.0
 * @date    2024/10/11
 * @license GUN General Public License(GPL)
 *
 * ------------------------------------------------
 * Remark   :Description
 * ------------------------------------------------
 * Change History:
 *    <Date>   |    <Version>    |   <Author>   |   <Description>
 * 2024/10/11  |     0.0.1.0     |      Dgg     |     createfile
 * 2024/10/12  |     0.0.1.1     |      Dgg     |     complete function
 * 2024/10/13  |     0.0.1.1     |      Dgg     |     add function init_dict_index
 */
#ifndef __CREATE_DICT_INDEX_H__
#define __CREATE_DICT_INDEX_H__

#include <vector>
#include <map>
#include <set>
#include <string>

#include "split.h"

using std::vector;
using std::pair;
using std::map;
using std::set;
using std::string;

/**
 * @brief this class is used to \n
 * get files and statistics words and words frequncy \n
 * and provide keywords recommend index
 */
class dictProducer{
public:
    static dictProducer *getInstance(const string &dir, splitTool *splitTool);
    void initialize();

private:
    dictProducer(const string &dir);
    dictProducer(const string &dir, splitTool *splitTool);

    dictProducer(const dictProducer&) = delete;
    dictProducer operator=(const dictProducer&) = delete;

    void init_dict();
    void init_index();

    void buildDict();
    void showDict() const;
    void storeDict(const string &path);
    void pushDict(const string &word);
    void buildEnDict();
    void buildCnDict();

    void buildIndex();
    void showFiles() const;

    bool is_initialized(const string &path);
    string getFiles(int i);

private:
    static dictProducer *_instance;
    string _workPath;
    vector<string> _files;
    vector<pair<string, int>> _dict;
    splitTool *_splitTool;
    map<string, set<int>> _index;
};

#endif